<?php

/**
 * This is the model class for table "auth_sources".
 *
 * The followings are the available columns in table 'auth_sources':
 * @property integer $id
 * @property string $type
 * @property string $name
 * @property string $host
 * @property integer $port
 * @property string $account
 * @property string $account_password
 * @property string $base_dn
 * @property string $attr_login
 * @property string $attr_firstname
 * @property string $attr_lastname
 * @property string $attr_mail
 * @property integer $onthefly_register
 * @property integer $tls
 *
 * The followings are the available model relations:
 * @property User[] $user
 */
class AuthSource extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return AuthSource the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'auth_sources';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('host, port, attr_login', 'required'),
            array('port, onthefly_register, tls', 'numerical', 'integerOnly'=>true),
            array('type, attr_login, attr_firstname, attr_lastname, attr_mail', 'length', 'max'=>30),
            array('name, host', 'length', 'max'=>60),
            array('account, account_password, base_dn', 'length', 'max'=>255),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, type, name, host, port, account, account_password, base_dn, attr_login, attr_firstname, attr_lastname, attr_mail, onthefly_register, tls', 'safe', 'on'=>'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'user' => array(self::HAS_MANY, 'User', 'auth_source_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'type' => 'Type',
            'name' => 'Name',
            'host' => 'Host',
            'port' => 'Port',
            'account' => 'Account',
            'account_password' => 'Account Password',
            'base_dn' => 'Base Dn',
            'attr_login' => 'Attr Login',
            'attr_firstname' => 'Attr Firstname',
            'attr_lastname' => 'Attr Lastname',
            'attr_mail' => 'Attr email',
            'onthefly_register' => 'Onthefly Register',
            'tls' => 'Tls',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('type',$this->type,true);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('host',$this->host,true);
        $criteria->compare('port',$this->port);
        $criteria->compare('account',$this->account,true);
        $criteria->compare('account_password',$this->account_password,true);
        $criteria->compare('base_dn',$this->base_dn,true);
        $criteria->compare('attr_login',$this->attr_login,true);
        $criteria->compare('attr_firstname',$this->attr_firstname,true);
        $criteria->compare('attr_lastname',$this->attr_lastname,true);
        $criteria->compare('attr_mail',$this->attr_mail,true);
        $criteria->compare('onthefly_register',$this->onthefly_register);
        $criteria->compare('tls',$this->tls);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
}